package com.jlp.source.service.impl;

import com.jlp.source.anno.DataSourceSign;
import com.jlp.source.domain.User;
import com.jlp.source.enums.ContextConst;
import com.jlp.source.mapper.UserMapper;
import com.jlp.source.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author lingpeng.jiang
 * @create 2022-01-09 14:39
 * @Description //TODO
 **/
@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    @DataSourceSign(ContextConst.DataSourceType.TIDB)
    public User selectUserById(Long userId) {
        return userMapper.selectUserById(userId);
    }

    @Override
    public User selectUserByDB1ById(Long userId){
        return userMapper.selectUserById(userId);
    }

    @Override
    //@Transactional(rollbackFor = Exception.class)
    @DataSourceSign(ContextConst.DataSourceType.MYSQL)
    public int updateMysqlUserById(User user){
        return userMapper.updateUserById(user);
    }

    @Override
    //@Transactional(rollbackFor = Exception.class)
    @DataSourceSign(ContextConst.DataSourceType.TIDB)
    public int updateTidbUserById(User user){
        int i = 10 / 0;
        return userMapper.updateUserById(user);
    }
}
